package lianxi;

import java.util.Scanner;

/**
 * 完全背包模版
 */
public class Main22 {
    public static void main(String[]args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int [][]f = new int[1010][1010];
        int []v = new int[1010];
        int []w = new int[1010];
        for(int i=1; i<=n; i++) {
            v[i] = sc.nextInt();
            w[i] = sc.nextInt();
        }

        for(int i=1;i<=n;i++) {
            for(int j=0;j<=m;j++) {
                for(int k=0; k*v[i] <= j;k++) {
                    f[i][j] = f[i-1][j];
                    if( j >= v[i]) {
                        f[i][j] = Math.max(f[i][j], f[i-1][ j-k*v[i] ] + k*w[i]);
                    }
                }

            }
        }
        System.out.print( f[n][m]);
    }
}
